<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Admin extends CI_Controller {

    /**
     *   网站后台
     *   王超伟
     * 	 2012.09.25
     * 	 art2006art#gmail.com
     */
    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('file');
        $this->load->helper('form');
        $this->load->database();
        $this->load->helper('captcha');
        $this->load->helper('string');
        $this->load->helper('func');
        $this->load->model('admin_process');
    }

    public function index() {
        $this->load->view('admin/header_view');
        $this->load->view('admin/index_view');
        $this->load->view('admin/footer_view');
    }

    //导航管理
    public function menu() {
        $this->load->view('admin/header_view');
        $this->load->view('admin/menu_view');
        $this->load->view('admin/footer_view');
    }

    //团队管理
    public function team() {
        $this->load->view('admin/header_view');
        $this->load->view('admin/team_view');
        $this->load->view('admin/footer_view');
    }

    //视频管理
    public function video() {
        $this->load->library('oss/ALIOSS');
        //$oss_sdk_service = new ALIOSS();

        $bucket = 'favorite_app';
        $options = array(
            'delimiter' => '/',
            'prefix' => '',
            'max-keys' => 10,
                //'marker' => 'myobject-1330850469.pdf',
        );

        //$data['response'] = $this->alioss->list_bucket();
        $response = $this->alioss->list_object($bucket, $options);

        $data['bucket_url'] = $response->header['x-oss-request-url'];
        $response = json_decode(json_encode(simplexml_load_string($response->body)), TRUE); //xml转成数组
        $data['flv'] = $response['Contents'];
        $this->load->view('admin/header_view', $data);
        $this->load->view('admin/video_view');
        $this->load->view('admin/footer_view');
    }

    //图片管理
    public function photos() {
        $this->load->view('admin/header_view');
        $this->load->view('admin/photos_view');
        $this->load->view('admin/footer_view');
    }

    /* 	
      //上传视频
      public function upVideo() {
      $this->load->view('admin/header_view');
      $this->load->view('admin/upVideo_view');
      $this->load->view('admin/footer_view');
      }
     */

    //上传图片
    public function upPhotos() {
        $this->load->view('admin/header_view');
        $this->load->view('admin/upPhotos_view');
        $this->load->view('admin/footer_view');
    }

    //友情链接管理
    public function links() {
        $this->load->view('admin/header_view');
        $this->load->view('admin/links_view');
        $this->load->view('admin/footer_view');
    }

    //网站设置
    public function setting() {
        $this->load->view('admin/header_view');
        $this->load->view('admin/setting_view');
        $this->load->view('admin/footer_view');
    }

    private function generate_captcha() {
//尝试做个验证码：）
        $vals = array(
            'word' => random_string('alnum', 6),
            'img_path' => './captcha/',
            'img_url' => base_url() . '/captcha/',
            'font_path' => './system/texb.ttf',
            'img_width' => 250,
            'img_height' => 30,
            'expiration' => 3600
        );
        $cap = create_captcha($vals);
        return $cap;
    }

    public function ajax_captcha() {//点击登陆验证码框，进行ajax请求
        $captcha_array = $this->generate_captcha();
        $_SESSION["captcha_word"] = strtolower($captcha_array["word"]);
        echo $captcha_array['image'];        
    }

    public function login() {
       // print_r($_SESSION);
        $captcha = $this->generate_captcha();
       // print_r($captcha);
        $_SESSION["captcha_word"] = strtolower($captcha["word"]); //赋值session
        $data['captcha_img'] = $captcha["image"];
        $this->load->view('admin/login', $data);
    }

    public function actionlogin() {
//首先判定验证码   
//        $captcha_word = strtolower($this->input->post('captcha', TRUE));
//        if ($_SESSION["captcha_word"] != $captcha_word) {
//            redirect('admin/admin/login', 'refresh');
//        }        
        $res = $this->admin_process->login_action();
     
        if ($res) {
               $_SESSION["statue"]="login";
            redirect('admin/admin/index', 'refresh');
        } else {
            redirect('admin/admin/login', 'refresh');
        }
        //  $this->load->view('admin/login');
    }

    public function logout() {
        unset($_SESSION["statue"]);
        redirect('admin/admin/login', 'refresh');
       
    }

}

/* End of file admin.php */
/* Location: ./application/controllers/admin.php */